package com.whosly.fast.web.controller;

import com.whosly.fast.web.quickly.config.AppConfig;
import com.whosly.fast.web.quickly.util.DateUtils;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import reactor.core.publisher.Mono;

@Controller
public class WelcomeController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private AppConfig appConfig;

    // 返回值 Mono 或者 String 都行，但是 Mono 代表着我这个返回 View 也是回调的。
    @GetMapping(path = {"", "/", "/index"})
    public Mono<String> viewIndex(Model model) {
        // Model 对象来进行数据绑定到视图
        model.addAttribute("now", DateUtils.getTime());
        model.addAttribute("env", this.appConfig.getEnv());

        // return 字符串，该字符串对应的目录在 resources/templates 下的模板名字。
        return Mono.just("index");
    }
}